/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bols;

import entity.Product;
import entity.User2;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionbean.CartRemote;

/**
 *
 * @author lab1
 */
public class BOL {

    CartRemote cart = lookupCartRemote();
    //phuont thuc them Cart

    public void addCart(String proID, String proName, Double price, int quantity) {
        cart.addToCart(proID, proName, price, quantity);
    }
    //phuong thuc show tat ca Cart

    public ArrayList<Product> showall() {
        return cart.getListcart();
    }
    //phuong thuc lay tong tien cua Cart

    public Double getTotalAmout() {
        return cart.getTotalAmount();
    }
    //phuong thuc delete 1 Cart

    public void removeProduct(String proID) {
        cart.removeProduct(proID);
    }
    //phuong thuc update lai Cart khi edit Cart

    public void updateProduct(ArrayList<Product> listpro) {
        cart.resetProduct(listpro);
    }
    //phuong thuc update User khi login thanh cong
    public void updateUser(User2 us) {
        cart.updateUse(us);
    }
    //Phuog thuc lay ra user khi login thanh cong
    public User2 showUser() {
        return cart.ShowUser();
    }

    private CartRemote lookupCartRemote() {
        try {
            Context c = new InitialContext();
            return (CartRemote) c.lookup("java:global/SHOPPINGCART2/SHOPPINGCART2-ejb/Cart!sessionbean.CartRemote");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
